import Vue from "vue";
import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
Vue.use(Vuex);

// 创建仓库 - 就是Vuex.Store() 的实例对象
const store = new Vuex.Store({
  // plugins: [createPersistedState(
  //   // { storage: window.sessionStorage, }
  // )],
  // 定义状态
  state: { 
    token: "", 
    type: '',
    username: '',
    // 路由数组
    routes: [],
  },

  mutations: { 
    set_token(state, payload) {
      state.token = payload;
    },
    set_type(state, payload) {
      state.type = payload;
    },
    set_username(state, payload) {
      state.username = payload;
    },
    set_routes(state, payload) {
      state.routes = payload;
    },
  },
});

// 导出仓库
export default store;
